<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>Document</title>
  <script>
  window.onload=function(){
    mytable = document.getElementById('mytable');
    //获取mytable中标签名为tr的子节点
    trs = mytable.getElementsByTagName("tr");
    len = trs.length;
    flag=true;                  							//开关变量
    for(i=0;i<len;i++){
        if(flag){
            trs[i].setAttribute('bgcolor','#cccccc');	//每隔一行设置背景色
            flag=false;
        }else{
            flag=true;
        }
    }
    //获取table的width属性值
    ww = mytable.getAttribute('width');
  }
  </script>
 </head>
 <body>
  <table id='mytable' align='center' width="80%" border='1'>
  <tr bgcolor='#cccccc'>
    <td>aaa</td><td>aaa</td><td>aaa</td>
  </tr>
  <tr>
    <td>bbb</td><td>bbb</td><td>bbb</td>
  </tr>
  <tr>
    <td>ccc</td><td>ccc</td><td>ccc</td>
  </tr>
  </table>
 </body>
</html>
